/*获取系统时间*/
/**
 * 
 * @date 时间显示格式
 */
function getNowTime(div, date) {
	//目前只支持24小时制,且自动补零,即:HH:mm:ss;	
	var now = new Date();
	
	date = date.replace("YYYY", now.getFullYear());
	date = date.replace("yyyy", now.getFullYear());
	date = date.replace("MM", this.appendZero(now.getMonth() + 1, 2));

	date = date.replace("dd", this.appendZero(now.getDate(), 2));

	date = date.replace("HH", this.appendZero(now.getHours(), 2));
		
	date = date.replace("mm", this.appendZero(now.getMinutes(), 2));
	date = date.replace("ss", this.appendZero(now.getSeconds(), 2));

	date = date.replace("week", getDay(now.getDay()));
	date = date.replace("{", "");
	date = date.replace("}", "");
	
	if ($(div).length > 0) {
		if ($(div).get(0).tagName == "INPUT") {
			$(div).attr('value', date);
		} else if ($(div).get(0).tagName == "SPAN") {
			$(div).html(date);
		}
	}
	return date;
}
/**
 * @div,用于显示的DOM元件
 * @date 时间显示格式
 * @ftime,函数执行间隔
 */
function setTime(div, date, ftime) {	
	setInterval(function() {getNowTime(div, date);}, ftime);
}
/*补零函数*/
/**
 * 
 * @data,时间数字.
 * @length,需要的长度,长度不够时补零
 */
function appendZero(date, length) {
	date = (date).toString();
	if (date.length < length) {
		for ( var i = 0; i < length - date.length; i++) {
			date = "0" + date;
		}
	}
	return date;
}
/*根据游客定时计算结束时间*/
/**
 * s
 * @start 开始时间
 * @sub 游客定时
 */
function setEndTime(start, sub) {
	var s = start.split(":");
	var send = 0;
	//游客定时,单位:分
	sub = parseInt(sub);
	s[0] = parseInt(s[0]);
	s[1] = parseInt(s[1]);
	s[2] = parseInt(s[2]);
	if (sub % 2 == 0) {
		s[0] = s[0] + sub / 2;

	} else {
		s[0] = s[0] + (sub - 1) / 2;
		s[1] = s[1] + 30;
	}

	if (s[1] >= 60) {
		s[0] = s[0] + 1;
		s[1] = s[1] - 60;
	}
	if (s[2] >= 0) {
		s[2] = "00";
		s[1] = s[1] + 1;
	}
	if (s[0] >= 24) {
		s[0] = s[0] - 24;
	}

	return appendZero(s[0], 2) + ":" + appendZero(s[1], 2) + ":" + "00";
}
/**
 * 
 * @nowtime 系统当前时间
 * @sub 游客从售票口到上船的时间
 */
function setStartTime(nowtime, sub) {
	var s = nowtime.split(":");
	var send = 0;
	sub = parseInt(sub);
	s[0] = parseInt(s[0]);
	s[1] = parseInt(s[1]);
	s[2] = parseInt(s[2]);
	s[1] = s[1] + 5;
	if (s[1] >= 60) {
		s[0] = s[0] + 1;
		s[1] = s[1] - 60;
	}
	return appendZero(s[0], 2) + ":" + appendZero(s[1], 2) + ":"
			+ appendZero(s[2], 2);
}
/**
 * 获取星期
 * @param {Object} date 当前星期
 */
function getDay(date) {
	var week;
	if (new Date().getDay() == 0)
		week = "日";
	if (new Date().getDay() == 1)
		week = "一";
	if (new Date().getDay() == 2)
		week = "二";
	if (new Date().getDay() == 3)
		week = "三";
	if (new Date().getDay() == 4)
		week = "四";
	if (new Date().getDay() == 5)
		week = "五";
	if (new Date().getDay() == 6)
		week = "六";
	return week;
}
